package cn.ecommerce.course.module.users.dal.mysql.users;

import java.util.*;

import cn.ecommerce.course.framework.common.pojo.PageResult;
import cn.ecommerce.course.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ecommerce.course.framework.mybatis.core.mapper.BaseMapperX;
import cn.ecommerce.course.module.users.dal.dataobject.users.UsersDO;
import org.apache.ibatis.annotations.Mapper;
import cn.ecommerce.course.module.users.controller.admin.users.vo.*;

/**
 * 电商平台用户 Mapper
 *
 * @author 恩
 */
@Mapper
public interface UsersMapper extends BaseMapperX<UsersDO> {

    default PageResult<UsersDO> selectPage(UsersPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<UsersDO>()
                .likeIfPresent(UsersDO::getAccount, reqVO.getAccount())
                .eqIfPresent(UsersDO::getPhone, reqVO.getPhone())
                .eqIfPresent(UsersDO::getEmail, reqVO.getEmail())
                .likeIfPresent(UsersDO::getNickname, reqVO.getNickname())
                .eqIfPresent(UsersDO::getAvatar, reqVO.getAvatar())
                .eqIfPresent(UsersDO::getStatus, reqVO.getStatus())
                .eqIfPresent(UsersDO::getGender, reqVO.getGender())
                .eqIfPresent(UsersDO::getBirthday, reqVO.getBirthday())
                .betweenIfPresent(UsersDO::getLastLoginTime, reqVO.getLastLoginTime())
                .eqIfPresent(UsersDO::getLoginIp, reqVO.getLoginIp())
                .orderByDesc(UsersDO::getId));
    }

}